package com.sts.transform.function;

import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.function.FunctionUtils;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;
import io.github.yindz.random.RandomSource;

import java.util.Map;

/**
 * @author lsl
 * @since 2025年07月09日 19:57
 */
public class RandEmailFunction extends AbstractFunction {

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1) {
        Number value = FunctionUtils.getNumberValue(arg1, env);
        return new AviatorString(RandomSource.internetSource().randomEmail(value.intValue()));
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        Number value = FunctionUtils.getNumberValue(arg1, env);
        String suffix = FunctionUtils.getStringValue(arg2, env);
        return new AviatorString(RandomSource.internetSource().randomEmail(value.intValue(), suffix));
    }

    @Override
    public String getName() {
        return "randEmail";
    }
}